{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import csv\n",
    "from numpy.random import seed\n",
    "from numpy.random import randn\n",
    "from scipy.stats import wilcoxon\n",
    "from prettytable import PrettyTable"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "files=[\"zscores/gmsd-zscores.csv\",\"zscores/lpips-zscores.csv\",\"zscores/psnr-zscores.csv\",\"zscores/ssim-zscores.csv\"]\n",
    "titles=[\"GMSD p-value\",\"LPIPS p-value\", \"PSNR p-value\",\"SSIM p-value\"]\n",
    "gmsd_p=[]\n",
    "lpips_p=[]\n",
    "psnr_p=[]\n",
    "ssim_p=[]\n",
    "scores=[gmsd_p,lpips_p,psnr_p,ssim_p]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "count=0\n",
    "for file in files:\n",
    "    EndoL2H=[]\n",
    "    DBPN=[]\n",
    "    SRGAN=[]\n",
    "    RCAN=[]\n",
    "\n",
    "    for line in open(file):\n",
    "        csv_row = line.replace(\"\\n\",\"\").split(\",\") \n",
    "        if \"val\" in csv_row:\n",
    "            continue\n",
    "        value=csv_row[0]\n",
    "        if \"EndoL2H\" in csv_row:\n",
    "            EndoL2H.append(float(value))\n",
    "        elif \"DBPN\" in csv_row:\n",
    "            DBPN.append(float(value))\n",
    "        elif \"RCAN\" in csv_row:\n",
    "            RCAN.append(float(value))\n",
    "        elif \"SRGAN\" in csv_row:\n",
    "            SRGAN.append(float(value))\n",
    "\n",
    "    algorithms=[EndoL2H,DBPN,RCAN,SRGAN]\n",
    "\n",
    "    for i in range(1,4):\n",
    "        seed(1)\n",
    "        stat, p = wilcoxon(algorithms[0], algorithms[i])\n",
    "        scores[count].append(p)\n",
    "    count+=1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "+-------------------------------------------------------------+\n",
      "|              Statistical Significance Analysis              |\n",
      "+---------------+--------------+--------------+---------------+\n",
      "|     Score     | EndoL2H-DBPN | EndoL2H-RCAN | EndoL2H-SRGAN |\n",
      "+---------------+--------------+--------------+---------------+\n",
      "|  GMSD p-value |   6.03e-06   |  2.46e-154   |    2.07e-28   |\n",
      "| LPIPS p-value |   1.82e-06   |  1.53e-176   |    4.09e-31   |\n",
      "|  PSNR p-value |    0.721     |   3.59e-27   |    2.49e-07   |\n",
      "|  SSIM p-value |   3.39e-23   |   1.78e-84   |    1.29e-16   |\n",
      "+---------------+--------------+--------------+---------------+\n"
     ]
    }
   ],
   "source": [
    "x = PrettyTable()\n",
    "x.field_names = [\"Score\", \"EndoL2H-DBPN\", \"EndoL2H-RCAN\", \"EndoL2H-SRGAN\"]\n",
    "\n",
    "for i in range(len(scores)):\n",
    "    x.add_row([titles[i],'{:.3g}'.format(scores[i][0]), '{:.3g}'.format(scores[i][1]),'{:.3g}'.format(scores[i][2])])\n",
    "\n",
    "print(x.get_string(title=\"Statistical Significance Analysis\"))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.2"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
